<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />
    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
  </div>
</template>

<script>
import subject from "@/api/edu/subject"

export default {
  data() {
    return {
      filterText: '',
      data2: [],// tree里面的数据
      defaultProps: {
        // 这里设置的是当你获取到json数据对应的属性名
        children: 'twoSubjectList',
        label: 'title'
      }
    }
  },
  created() {
    this.getAllSubjectList()
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true
      return data.title.indexOf(value) !== -1
    },
    getAllSubjectList(){
      subject.getSubjectList()
      .then(response => {
        this.data2 = response.data.list
      }).catch(error => {

      })
    }
  }
}
</script>